package com.turing.model.caller.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.turing.common.response.model.ResVO;
import com.turing.common.util.HttpUtils;
import com.turing.model.caller.handler.OcrCallerHandler;
import com.turing.model.caller.service.ModelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class ModelServiceImpl implements ModelService {

    private static final Logger logger = LoggerFactory.getLogger(ModelService.class);

    @Override
    public boolean statusOK( String host,String cardNo ) {

        String statusUrl = "http://" + host  + "/api/gpu/info";
        String statusResponse = "";
        try{
            statusResponse = HttpUtils.doGet(statusUrl);
            ResVO<JSONObject> resVO = JSONObject.parseObject(statusResponse, new TypeReference<ResVO<JSONObject>>(){});
            if(resVO.getCode() != null && resVO.getCode().equals("0")){
                JSONObject data = resVO.getData();
                if(data != null && Integer.parseInt(data.get(cardNo).toString()) == 0 ){
                    return true;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return false;
    }

}
